"""
chatGPT-5编写，提示词：
现在的数据集格式是
{"sentence":"Ian volunteered to eat Dennis's menudo after already having a bowl because _ despised eating intestine.","option1":"Ian","option2":"Dennis","answer":"2"}
{"sentence":"Ian volunteered to eat Dennis's menudo after already having a bowl because _ enjoyed eating intestine.","option1":"Ian","option2":"Dennis","answer":"1"}
这种，现在我要转成
{
  "type": "text2text",
  "instances": [
    {
      "input": "Instruction: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.",
      "output": "If you have any questions about my rate or find it necessary to increase or decrease this project's scope, please let me know."
    },
    {
      "input": "Instruction: Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to the reader? These tones include Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, and Excited. Hi Jen, \nI hope you're well. Can we catch up today? I'd appreciate your input on my presentation for tomorrow's meeting. I'd especially love it if you could double-check the sales numbers with me. There's a coffee in it for you!",
      "output": "Confident"
}。
新格式中，input的值是原格式sentence加option1加option2的组合；output的值为：根据answer中的1或者2从option1或者option2中选择并填入。
请写一个Python程序实现以上任务，原格式与新格式都是磁盘中的文件
"""
import json

def convert_dataset(input_file, output_file):
    instances = []
    
    with open(input_file, "r", encoding="utf-8") as f:
        for line in f:
            if not line.strip():
                continue
            data = json.loads(line.strip())
            
            # 构造 input
            input_text = f"Sentence: {data['sentence']} Option1: {data['option1']} Option2: {data['option2']}"
            
            # 根据 answer 选择 output
            if data["answer"] == "1":
                output_text = data["option1"]
            elif data["answer"] == "2":
                output_text = data["option2"]
            else:
                raise ValueError(f"Unexpected answer value: {data['answer']}")
            
            instances.append({
                "input": input_text,
                "output": output_text
            })
    
    new_data = {
        "type": "text2text",
        "instances": instances
    }
    
    with open(output_file, "w", encoding="utf-8") as f:
        json.dump(new_data, f, ensure_ascii=False, indent=2)


if __name__ == "__main__":
    convert_dataset("/liub/zyf/Fine-tuning/LMFlow-1.0.0/data/winogrande_l/train/changed_tojson.json", "output.json")

